<!-- jQuery 2.2.3 -->
<script src="${request.contextPath}/static/oms/default/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${request.contextPath}/static/oms/default/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${request.contextPath}/static/oms/default/plugins/fastclick/fastclick.js"></script>
<!-- Slimscroll -->
<script src="${request.contextPath}/static/oms/default/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- AdminLTE App -->
<script src="${request.contextPath}/static/oms/default/dist/js/app.js"></script>
<!-- 以上JS为页面必须 -->

<script src="${request.contextPath}/static/oms/default/plugins/jQuery/datetimepicker/jquery.datetimepicker.full.js"></script>

<!-- DataTables -->
<script src="${request.contextPath}/static/oms/default/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${request.contextPath}/static/oms/default/plugins/datatables/dataTables.bootstrap.min.js"></script>

<script src="${request.contextPath}/static/oms/default/plugins/jQuery/validate/jquery.validate.js"></script>
<script src="${request.contextPath}/static/oms/default/plugins/jQuery/validate/jquery.validate.methods.js"></script>
<script src="${request.contextPath}/static/oms/default/dist/js/base.js"></script>

<script type="text/javascript">
	$(function() {
		$.ajax({
	        url:'/system/authority/resource/getMainMenu',
	        type:'get',
	        async: false,  
	        dataType:'json',  
	        success:function(data){
	        	var btnSep = 0;
	        	$.each(data, function(i, item){
	        		if(item.pid==='001'){
	        			btnSep++;
	        			
	        			/*
	        			*判断节点下面是否有子节点
	        			*/
	        			var itemLength =0;
	        			$.each(data, function(iSons, itemSons){
		            		if(item.id===itemSons.pid){
	            				itemLength++;
		            		}
		            	});
		            	if(itemLength<1){
		            		
		            		var htmlString=$('#sidebar-menu').html()
		            		+'<li id="treeview-'+item.id+'" class="treeview">'
		    				+'	<a target="navTab" href="'+item.attributes.url+'">'
		    				+'		<i class="fa fa-folder"></i> <span>'+item.name+'</span> </i>'
		    				+'	</a>'
		    				+'</li>'
		    				
		            		$('#sidebar-menu').html(htmlString);
						}else{
							var htmlString=$('#sidebar-menu').html()
		            		+'<li id="treeview-'+item.id+'" class="treeview">'
		    				+'	<a>'
		    				+'		<i class="fa fa-folder"></i> <span>'+item.name+'</span>'
		    				+'		<span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i></span>'
		    				+'	</a>'
		    				+'	<ul id="treeview-menu-'+item.id+'" class="treeview-menu">'
		    				+'  </ul>'
		    				+'</li>'
		            		$('#sidebar-menu').html(htmlString);
						}
		        		
		            	$.each(data, function(iSons, itemSons){
		            		if(item.id===itemSons.pid){
		            			var sonsLength = 0;
		            			$.each(data, function(iSonsTest, itemSonsTest){
		            				if(itemSons.id==itemSonsTest.pid){
		            					sonsLength++;
		            				}
		            			});
		            			if(sonsLength<1){
		            				
		            				var htmlStringSons=$('#treeview-menu-'+item.id).html()
		            				+'<li>'
									+'	<a target="navTab" href="'+itemSons.attributes.url+'">'
									+'		<i class="fa fa-inbox text-red"></i>'
									+'		<span>'+itemSons.name+'</span>'
									+'	</a>'
									+'</li>'
								
	            					$('#treeview-menu-'+item.id).html(htmlStringSons);
								}else{
									var htmlStringSons=$('#treeview-menu-'+item.id).html()
		            				+'<li>'
									+'	<a>'
									+'		<i class="fa fa-inbox text-red"></i>'
									+'		<span>'+itemSons.name+'</span>'
				    				+'		<span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i></span>'
									+'	</a>'
				    				+'	<ul id="treeview-menu-'+itemSons.id+'" class="treeview-menu">'
				    				+'  </ul>'
									+'</li>'
									$('#treeview-menu-'+item.id).html(htmlStringSons); 
	            					_each(iSons,itemSons,data,itemSons.id);
								}
		            		}
		            	}); 
	            	}
	        	});
	        }  
	    });
});

/*递归方法 */
function _each(iSons,itemSons,data,itemSonsId){
	$.each(data, function(iSons, itemSonsSons){
		if(itemSonsId===itemSonsSons.pid){
			var sonsLength = 0;
			$.each(data, function(iSonsTest, itemSonsTest){
				if(itemSonsSons.id===itemSonsTest.pid){
					sonsLength++;					
		 		}
			});			
		    if(sonsLength<1){
		    	var htmlStringSons=$('#treeview-menu-'+itemSons.id).html()
      				+'<li>'
				+'	<a target="navTab" href="'+itemSonsSons.attributes.url+'">'
				+'		<i class="fa fa-inbox text-red"></i>'
				+'		<span>'+itemSonsSons.name+'</span>'
				+'	</a>'
				+'</li>'
			
  					$('#treeview-menu-'+itemSons.id).html(htmlStringSons);
			}else{
				var htmlStringSons=$('#treeview-menu-'+itemSons.id).html()
      				+'<li>'
				+'	<a>'
				+'		<i class="fa fa-inbox text-red"></i>'
				+'		<span>'+itemSonsSons.name+'</span>'
   				+'		<span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i></span>'
				+'	</a>'
   				+'	<ul id="treeview-menu-'+itemSonsSons.id+'" class="treeview-menu">'
   				+'  </ul>'
				+'</li>'
				$('#treeview-menu-'+itemSons.id).html(htmlStringSons); 
				_each(iSons,itemSons,data,itemSonsSons.id);
			}
		}
	});
}
</script>
		
<script type="text/javascript">
	var list_ajax;
	var date_ajax;
	var search_ajax;
	//当你需要多条件查询，你可以调用此方法，动态修改参数传给服务器
	window.reloadTable = function(oTable) {
		//oTable.settings()[0].ajax.data = param;
		oTable.ajax.reload();
	}
</script>